package com.ryt.tuangou.controller;

import com.ryt.tuangou.pojo.User;
import com.ryt.tuangou.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController {

    @Autowired
    private UserService userService;

    //注册用户
    @PostMapping("/saveUser")
    public Boolean saveUser(@RequestBody User user){

        return userService.saveUser(user);
    }
    //用户登录
    @PostMapping("/loginIn")
    public Boolean loginIn(@RequestBody User user){
        //如果用户名或密码为空抛出错误
        if(user.getUserName()==null||user.getUserPwd()==null){
            throw new RuntimeException("用户名或密码不能为空");
        }
        return userService.loginIn(user);
    }
}
